package org.example.struct.array;

/**
 * @author liyishan
 * @date 2024/2/27 10:23
 * @apiNote
 */

public class Test00007Reverse {

    public int reverse(int x) {
        int res = 0;
        while (x != 0) {
            if (res < Integer.MIN_VALUE / 10 || res > Integer.MAX_VALUE / 10) {
                return 0;
            }
            int result = x % 10;
            x /= 10;
            res = res * 10 + result;
        }
        return res;
    }
}
